<?php
/**
 * Created by PhpStorm.
 * User: jack Wang
 * Date: 2021/10/29
 * Time: 13:37
 */

class Activity_service extends MY_Service
{
    //redis连接
    private $conn;

    public function __construct()
    {
        parent::__construct();
        $this->load->model('Activity_model');
        $this->load->model('Users_model');
        $this->load->model('Prop_model');
        $this->conn = getRedis();
        //活动的数据放在三库
        $this->conn->selectDb(3);
    }

    //掷骰子操作
    public function rollDice($uid)
    {
        if ($uid == 0) {
            fail(400, '参数错误');
        }
        $lock = $uid . '_rollDiceLock'; //redis防止并发点击锁
        if (!$this->conn->setNxExpire($lock, 1, 3)) {
            fail(400, '点击太快了，稍后再试');
        }
        $num = $this->getDiceNum($uid);
        if (!$num) {
            $this->conn->del($lock); //移除锁
            fail(400, '骰子数量不足');
        }
        //执行掷骰子操作(有多少骰子，全部掷出)
        $step = 0;
        for ($i = 1; $i <= $num; $i++) {
            $step += rand(1, 6);
        }
        if ($step <= 0) {
            $this->conn->del($lock); //移除锁
            fail(400, '前进步数计算错误');
        }
        //更新用户已经走的步数
        $step_key = $uid . '_diceStep';
        $this->conn->incrBy($step_key, $step);
        //更新步数排行榜 (向有序set中指定id加指定的步长)
        $step_rank_key = 'stepRank';
        $after_step = $this->conn->zIncrBy($step_rank_key, $step, $uid);

        //获取到的积分奖励(每一步获取10积分)
        $score = $step * 10;
        //额外金币奖励
        $coin = $this->getAward($step, $after_step);
        //将获得的全部奖励记录到本次骰子活动的记录表中
        $this->Activity_model->addScore($uid, $step, $score, $coin, $after_step, $num);
        //将积分奖励增加到用户账户上
        $this->Activity_model->updateScore($uid, $score);
        if ($coin > 0) {
            $text = "活动掷骰子获得的额外金币奖励{$coin}个";
            $this->Activity_model->changeCoins($uid, $coin, $text);
        }
        $res = [
            'step' => $step,
            'score' => $score,
            'use_num' => $num,
            'coin' => $coin,
        ];
        $this->conn->del($lock);//移除锁
        success($res);
    }

    // 获得骰子(首次登录、每日签到)
    public function addDice($uid, $action)
    {
        //将当天日期上锁
        $lock_key = date('Y-m-d', time()) . '_' . $uid . "_{$action}_" . '_dice';
        $status = $this->conn->setNx($lock_key, 1);
//        $this->conn->expire($lock_key, 86400);
        //测试
        $this->conn->expire($lock_key, 3);
        if ($action == "Login"){
            $type = 3;
        }else{
            $type = 4;
        }
        //只有首次进来才加骰子
        $data = [];
        if ($status) {
            $dice_key = $uid . '_diceNum';
            $this->conn->expire($dice_key, 86400 * 7);
            $this->conn->incr($dice_key);
            $res = $this->getMagicBox($uid,$type);
            if ($res['code'] == 200) {
                //成功获得魔盒
                $data['magicBox'] = $this->Prop_model->getPropFiledsById(24, 'prop_name,image,desc');
                $data['magicBox'][0]['image'] = config_item('img_url') . $data['magicBox'][0]['image'];
            }
            return $data;
        }
        return false;
    }

    // 掷骰子的额外奖励
    public function getAwardList()
    {
        return [
            [
                'step' => 10,
                'coin' => 100
            ],
            [
                'step' => 20,
                'coin' => 200,
            ],
            [
                'step' => 50,
                'coin' => 500,
            ],
            [
                'step' => 100,
                'coin' => 1000,
            ],
            [
                'step' => 200,
                'coin' => 2000,
            ],
            [
                'step' => 500,
                'coin' => 10000,
            ],
        ];
    }

    // 获取用户可以使用的骰子数量
    public function getDiceNum($uid)
    {
        //获取用户的骰子数
        $key = $uid . '_diceNum';
        //从redis中获取用户全部的骰子数量
        $allNum = $this->conn->get($key);
        //获取用户已经消耗的骰子数量
        $useNum = $this->Activity_model->getUseNum($uid);
        //返回剩下的骰子数量，不够的话返回false
        return ($allNum - $useNum >= 0) ? $allNum - $useNum : false;
    }

    // 获取用户可以获得的额外金币奖励
    public function getAward($step, $after_step)
    {
        //获取用户本次掷骰子获取的额外奖励
        $list = $this->getAwardList();
        $list = array_column($list, null, 'step');
        $award = 0;
        //获取用户可以获得的额外奖励
        foreach ($list as $k => $v) {
            if ($after_step >= $v['step'] && $after_step - $step < $v['step']) {
                $award += $v['coin'];
            }
        }
        return $award;
    }

    //活动首页
    public function diceIndex($uid)
    {
        if (!$uid) {
            fail(400, '参数错误!');
        }
        //全部榜单
        $list = $this->userStepRank();
        //用户距离榜单的数据
        $userInfo = $this->stepDistance($list, $uid);
        //用户剩下的骰子数量
        $num = $this->getDiceNum($uid);
        $userInfo['num'] = $num;
        //用户走过的全部步数
        $key = $uid . "_diceStep";
        $userStep = $this->conn->get($key);
        $award = $this->getAwardList();
        foreach ($award as $k => $v) {
            if ($userStep >= $v['step']) {
                unset($award[$k]);
            }
        }
        $data = [
            'userInfo' => $userInfo,
            'award' => $award,
        ];
        success($data);
    }

    //榜单页面
    public function stepRank($uid)
    {
        //获取全部榜单
        $list = $this->userStepRank();
        //取榜单前三
        $userRank3 = array_slice($list, 0, 3);
        //取前三名用户的详细信息
        $userInfo3 = $this->Activity_model->stepRank($userRank3);
        foreach ($userInfo3 as $k => $v) {
            foreach ($userRank3 as $kk => $vv) {
                if ($v['id'] == $vv['uid']) {
                    $userRank3[$kk]['nickname'] = $v['nickname'] ? $v['nickname'] : '';
                    $userRank3[$kk]['image'] = $v['image'] ? $v['image'] : '';
                }
                $userRank3[$kk]['award'] = $this->rankAward()[$vv['rank']];
            }
        }
        //获取用户的步数信息
        $userRank = $this->stepDistance($list, $uid);
        $userInfo = $this->Activity_model->commonQuery('nickname,image', ['id' => $uid], 'users');
        $userRank['nickname'] = $userInfo[0]['nickname'];
        $userRank['image'] = $userInfo[0]['image'];
        $data = [
            'rankList' => $userRank3,
            'userInfo' => $userRank
        ];
        success($data);
    }

    //获取完成的用户排行榜单
    public function userStepRank()
    {
        //获取榜单的前3名数据
        $step_rank_key = 'stepRank';
        //获取全部的榜单
        $rank = $this->conn->zRevRange($step_rank_key, 0, -1, true);
        $rank1 = 1;
        foreach ($rank as $k => $v) {
            $res[] = [
                'uid' => $k,
                'step' => $v,
                'rank' => $rank1
            ];
            $rank1++;
        }
        return $res;
    }

    //获取用户在榜单的位置以及距离上一名需要的步数
    public function stepDistance($list, $uid)
    {
        $uidKeysArray = array_column($list, null, 'uid');
        //前三名
        $uidKeysArray3 = array_slice($uidKeysArray, 0, 3, true);
        //用户在榜单中
        if (array_key_exists($uid, $uidKeysArray3)) {
            foreach ($list as $k => $v) {
                if ($v['uid'] == $uid) {
                    if ($v['rank'] == 1) {
                        $distance = 0;
                    } else {
                        $distance = $list[$k - 1]['step'] - $v['step'];

                    }
                    $res = [
                        'uid' => $uid,
                        'rank' => $v['rank'],
                        'step' => $v['step'],
                        'distance' => $distance
                    ];
                }
            }
        } else {
            //用户不在榜单中,则距离榜单最后一名需要的步数
            $end = end($uidKeysArray3);
            $res = [
                'uid' => $uid,
                'rank' => $uidKeysArray[$uid]['rank'],
                'step' => $uidKeysArray[$uid]['step'],
                'distance' => $end['step'] - $uidKeysArray[$uid]['step']
            ];
        }
        return $res;
    }

    //榜单前三名活动结束之后可以获得的奖励列表
    public function rankAward()
    {
        return [
            1 => '100000金币',
            2 => '50000金币',
            3 => '10000金币',
        ];
    }

    //获取盲盒操作
    public function getBlindBox($uid, $num)
    {
        $key = $uid . "_BlindBoxNum";
        $res = $this->conn->incrBy($key, $num);
        if ($res) {
            $data = [
                'uid' => $uid,
                'num' => $num,
            ];
            return $data;
        }
    }

    //开启盲盒操作
    public function openBlindBox($uid, $num)
    {
        if ($num <= 0) {
            response(400, '开启盲盒数量错误');
        }
        //获取我的盲盒数量
        $key = $uid . "_BlindBoxNum";
        $boxNum = $this->conn->get($key);
        if ($boxNum < $num) {
            response(400, '盲盒数量不够');
        }
        //锁
        $lockKey = $uid . "_openBlindBoxLock";
        if (!$this->conn->setNxExpire($lockKey, 1, 3)) {
            response(400, '系统繁忙，稍后重试');
        }
        //扣除盲盒数量
        $this->conn->incrBy($key, -$num);
        //开启盲盒获得的字符奖励
        $charList = $this->blindBox($num);
        //将字符增加到我的字符集中
        $myCharKey = $uid . '_charNum';
        foreach ($charList as $k => $v) {
            //将中奖信息存储起来
            $this->conn->hIncrBy($myCharKey, $k, $v);
        }
        //将中奖信息记录到活动流水表中
        $awardData = json_encode($charList);
        $this->Activity_model->addActivityTurnover($uid, $num, 1, $awardData);
        //移除锁
        $this->conn->del($lockKey);
        response(200,'成功',$charList);
    }

    //返回抽取盲盒的获取的全部字符以及数量
    public function blindBox($num)
    {
        //盲盒的全部字符获取概率
        $rate = [
            0 => 333,   //W
            1 => 333,   //Y
            2 => 222,   //Q
            3 => 111,   //G
            4 => 1,     //幸运大奖 1w
        ];
        $res = [];
        for ($i = 0; $i < $num; $i++) {
            $index = rateGetAward($rate);
            $res[$index] += 1;
        }
        return $res;
    }

    //字符兑换列表
    public function charExchangeList()
    {
        return [
            [
                'propId' => 0, //一个金币
                'useChar' => [],
                'num' => -1, //无上限
            ],
            [
                'propId' => '1',    //道具id
                'useChar' => [0, 1], //需要的字符
                'num' => 10,  //兑换上限
            ],
            [
                'propId' => '2',
                'useChar' => [0, 1, 2],
                'num' => 5,
            ],
            [
                'propId' => '3',
                'useChar' => [0, 1, 2],
                'num' => 5,
            ],
            [
                'propId' => '4',
                'useChar' => [0, 1, 2, 3],
                'num' => 1
            ],
        ];
    }

    // 字符兑换道具
    public function charExchange($uid, $index)
    {
        $awardList = $this->charExchangeList();
        $awardListItem = $awardList[$index]; //通过index找到当前用户兑换的道具
        if (empty($awardListItem)) {
            fail(400, '配置错误!');
        }
        //查看用户字符是否足够兑换该道具
        $charList = $this->Activity_model->getChars($uid);
        if (empty($charList)) {
           fail(400, '字符数量不够!');
        }
        foreach ($awardListItem['useChar'] as $k => $v) {
            if (empty($charList[$k]) || $charList[$k] < 1) {
                fail(400, '字符数量不够!');
            }
        };
        //到这里说明字符数量足够
        //上锁
        $lockKey = "charExchange_" . $uid;
        if (!$this->conn->setNxExpire($lockKey, 1, 3)) {
            fail(400, '系统繁忙，稍后重试!');
        }
        //非金币兑换
        if ($awardListItem['propId']) {
            //通过查询兑换记录查看用户是否已经达到兑换限制
            $usedNum = $this->Activity_model->getExchangePropNum($uid, $index);
            if ($usedNum[0]['num'] >= $awardListItem['num']) {
                fail(400, '该道具兑换已达上限!');
            }
            //首先扣除字符道具
            foreach ($awardListItem['useChar'] as $k => $v) {
                $res = $this->Activity_model->changeCharNum($uid, $k, -1);
                if (!$res) {
                    //扣除失败，移除锁
                    $this->conn->del($lockKey);
                    fail(400, '字符数量不够!');
                }
            }
            //获取兑换的道具名
            $prop_name = $this->Activity_model->getPropNameById($awardListItem['propId']);
            //将道具增加到用户的背包中
            $this->Activity_model->addRucksack($uid, $awardListItem['propId'], 1, '字符兑换道具' . $prop_name[0]['prop_name']);
            $useIndex = implode(',', $awardListItem['useChar']);
        } else {
            //金币兑换，使用最多的字符兑换金币
            $max = 0;
            foreach ($charList as $k => $v) {
                if ($v > $max) {
                    $max = $v;
                    $useChar = $k;
                }
            }
            //扣除字符
            $res = $this->Activity_model->changeCharNum($uid, $useChar, -1);
            if (!$res) {
                $this->conn->del($lockKey);
                fail(400, '字符数量不够!');
            }
            //向用户账户增加金币
            $this->Activity_model->changeCoins($uid, 1,'字符兑换获得金币');
            $useIndex = $useChar;
        }
        $this->conn->del($lockKey);
        $this->Activity_model->addExchangeLog($uid, $useIndex, $index, time());
        success('','兑换成功');
    }

    //用户字符已兑换奖励列表
    public function charExchangeAward($uid)
    {
        if (!$this->Users_model->checkUser($uid)) {
            fail(400, '参数错误!');
        }
        //从兑换记录流水中获取到我的兑换记录
        $exchangeAward = $this->Activity_model->getExchangePropLog($uid);
        //字符兑换的全部奖励
        $exchangeList = $this->charExchangeList();
        $exchangeAward = array_column($exchangeAward, null, 'award_index');
        //通过字符兑换全部奖励得到兑换的道具奖励prop_id
        foreach ($exchangeList as $k => $v) {
            foreach ($exchangeAward as $k1 => $v1) {
                if ($k == $k1) {
                    $exchangeAward[$k1]['propId'] = $v['propId'];
                    //通过prop_id得到道具的名称
                    $prop_name = $this->Activity_model->getPropNameById($v['propId']);
                    if (!empty($prop_name[0]['prop_name'])) {
                        $data[] = [
                            'prop_id' => $v['propId'],
                            'num' => $exchangeAward[$k1]['num'],
                            'prop_name' => $prop_name[0]['prop_name']
                        ];
                    } else {
                        $data[] = [
                            'prop_id' => $v['propId'],
                            'num' => $exchangeAward[$k1]['num'],
                            'prop_name' => "一个金币"
                        ];
                    }
                }
            }
        }
        success($data);
    }

    //用户字符兑换字符首页
    public function charExchangeAwardIndex($uid)
    {
        if (!$this->Users_model->checkUser($uid)) {
            fail(400, '没有该用户!');
        }
        //获取字符兑换的奖励列表
        $charExchangeList = $this->charExchangeList();
        //获取我已经兑换的奖励列表
        $charExchangedList = $this->Activity_model->getExchangePropLog($uid);
        $charExchangedList = array_column($charExchangedList, null, 'award_index');
        //获取我的字符列表
        $charList = $this->Activity_model->getChars($uid);
        //按index排序
        ksort($charList);
        foreach ($charExchangeList as $k => $v) {
            foreach ($charExchangedList as $k1 => $v1) {
                $propName = $this->Activity_model->getPropNameById($charExchangeList[$k]['propId']);
                $used = 0;
                if ($k == $k1) {
                    $used = $charExchangedList[$k1]['num'];
                }
            }
            $list[] = [
                'prop_id' => $charExchangeList[$k]['propId'],
                'prop_name' => $charExchangeList[$k]['propId'] ? $propName[0]['prop_name'] : "一个金币",
                'num' => $charExchangeList[$k]['num'],
                'used' => $used,
                'needChar' => $charExchangeList[$k]['useChar'],
            ];
        }
        $data['awardList'] = $list;
        $data["hasCharList"] = $charList;
        success($data);
    }

    //盲盒交友
    //放入纸条
    public function sendBlindBoxNote($data)
    {
        //查看是否每日免费
        $key = "sendBlindBoxFriendFree_" . date('Ymd') . '_' . $data['uid'];
        $lockKey = "sendBlindBoxFriendLock_" . $data['uid'];
        //防止同用户多次点击，上锁
        if (!$this->conn->setNxExpire($lockKey,1,3)) {
            fail(400, '点击太快了，稍后重试');
        }
        //敏感词过滤
        $response = checkTxt($data['content']);
        //含有敏感词
        if (!$response['status']) {
            $this->conn->del($lockKey);//移除锁
            fail(400, $response['msg']);
        }
        //已经存在该键则不是免费
        $status = $this->conn->exists($key);
        if ($status) {
            //扣10金币
            $text = "向交友盲盒放入纸条";
            $res = $this->Activity_model->changeCoins($data['uid'], -10,$text);
            if (!$res) {
                $this->conn->del($lockKey);//移除锁
                fail(400, '金币不足');
            }
        } else {
            //每日免费
            $this->conn->set($key, 1, 2 * 86400);
        }
        //图片上传
        $dir = PHP_OS == "WINNT" ? "D:/image/blindBox/".date('Ymd') : "/var/www/data/image/blindBox/".date('Ymd');
        $res = uploadImages('image',$dir);
        if (is_array($res)) {
            $data['images'] = implode($res, ',');
        }
        $data['init_time'] = time();
        $res = $this->Activity_model->addBlindBoxFriend($data);
        //盲盒交友有概率获取魔盒
        $resData = $this->getMagicBox($data['uid'],2);
        $magicBox = [];
        if ( $resData['code'] == 200){
            $magicBox = $this->Prop_model->getPropFiledsById(24,'prop_name,image,desc');
        }
        if (!$res) {
            if ($status) {
                //失败则将金币加回去
                $this->Activity_model->changeCoins($data['uid'], 10,'交友盲盒放入纸条失败，返回金币');
            } else {
                //将首次免费机会返回
                $this->conn->del($key);
            }
            $this->conn->del($lockKey);
            fail(400, '放入纸条失败!');
        }
        $this->conn->del($lockKey);
        success($magicBox, '放入纸条成功!');
    }

    //抽取纸条
    public function getBlindBoxNote($data)
    {
        //抽取纸条是否每日免费
        $key = "getBlindBoxFriendFree_" . date('Ymd') . '_' . $data['uid'];
        //防止多次点击锁
        $lockKey = "getBlindBoxFriendLock_" . $data['uid'];
        if(!$this->conn->setNxExpire($lockKey,1,3)){
            fail(400,'点击太快了，稍后重试');
        }
        if ($this->conn->exists($key)) {
            //扣金币
            $res = $this->Activity_model->changeCoins($data['uid'], -10,'从交友盲盒中抽取纸条');
            if (!$res) {
                //移除锁
                $this->conn->del($lockKey);
                fail(400, '金币不足');
            }
        } else {
            //每日免费次数
            $this->conn->set($key, 1, 2 * 86400);
        }
        //获取纸条
        $Note = $this->Activity_model->getBlindBoxNote($data['uid'], $data['type']);
        //
        if (!$Note) {
            //移除锁
            $this->conn->del($lockKey);
            fail(400, '没有纸条可以获取');
        }
        $res = [
            'code' => $Note[0]['code'] ? $Note[0]['code'] : '',
            'content' => $Note[0]['content'] ? $Note[0]['content'] : '',
            'images' => $Note[0]['images'] ? explode(',', $Note[0]['images']) : '',
        ];
        //记录抽取记录
        $this->Activity_model->addGetBlindBoxFriend($data['uid'], $Note[0]['id']);
        //移除锁
        $this->conn->del($lockKey);
        success($res);
    }

    //我的纸条
    public function myBlindBoxNote($uid, $type)
    {
        //获取我放入的纸条
        $res = $this->Activity_model->myBlindBoxNote($uid, $type);
        foreach ($res as $k => $v) {
            $response[$k]['code'] = $v['code'];
            $response[$k]['type'] = $v['type'];
            $response[$k]['content'] = $v['content'];
            $response[$k]['images'] = $v['images'];
            if ($v['images']) {
                $response[$k]['images'] = explode(',', $v['images']);
            }
        }
        success($response);
    }

    //魔盒开启操作
    public function openMagicBox($uid, $num)
    {
        if (!$this->conn->setNxExpire(RedisKey::MAGIC_OPEN_LOCK . $uid, 1, 2)) {
            $this->serviceResponse(400, '操作太快了!');
        }
        //查询用户魔盒和钥匙的数量
        $res = $this->Activity_model->getMagicBoxNum($uid);
        if (empty($res)) {
            $this->conn->del(RedisKey::MAGIC_OPEN_LOCK . $uid);
            return $this->serviceResponse(400, '魔盒或钥匙数量不足!');
        }
        $magic = array_column($res, null, 'prid');
        if (empty($magic[24]) || $magic[24]['num'] < $num) {
            $this->conn->del(RedisKey::MAGIC_OPEN_LOCK . $uid);
            return $this->serviceResponse(400, '魔盒数量不足');
        }
        if (empty($magic[25]) || $magic[25]['num'] < $num) {
            $this->conn->del(RedisKey::MAGIC_OPEN_LOCK . $uid);
            return $this->serviceResponse(400, '钥匙数量不足');
        }
        //扣除背包中的魔盒道具数量 开启事务
        $this->Activity_model->db->trans_begin();
        $res = $this->Activity_model->addRucksack($uid, 24, -$num, "开启魔盒*{$num}个，扣除魔盒");
        if (!$res) {
            //失败回滚
            $this->Activity_model->db->trans_rollback();
            $this->conn->del(RedisKey::MAGIC_OPEN_LOCK . $uid);
            return $this->serviceResponse(400, '魔盒道具数量不足');
        }
        //扣除背包中的钥匙数量
        $res = $this->Activity_model->addRucksack($uid, 25, -$num, "开启魔盒*{$num}个,扣除钥匙");
        if (!$res) {
            //失败回滚
            $this->Activity_model->db->trans_rollback();
            $this->conn->del(RedisKey::MAGIC_OPEN_LOCK . $uid);
            return $this->serviceResponse(400, '钥匙道具数量不足');
        }
        //获取开启魔盒可以获得的道具id以及概率
        $award = $this->getMagicAwardList($num);
        if (!$award) {
            //失败回滚
            $this->Activity_model->db->trans_rollback();
            $this->conn->del(RedisKey::MAGIC_OPEN_LOCK . $uid);
            return $this->serviceResponse(400, '开启魔盒失败，请重试');
        }
        //记录本次的金币和道具流水以及魔盒的开启记录
        $awardList = [];
        foreach ($award as $k => $v) {
            //记录开启魔盒的流水
            $res1 = $this->Activity_model->addOpenMagicBox($uid, $k, $v['type'],$v['num']);
            if ($v['type'] == 1) {
                //金币流水
                $res = $this->Activity_model->changeCoins($uid, $k * $v['num'], "开启魔盒获得金币奖励");
                $awardList[] = [
                    'award' => $k."金币*".$v['num'],
                    'img' => '',
                ];
            } else {
                //道具流水
                $res = $this->Activity_model->addRucksack($uid, $k, $v['num'], '开启魔盒获得道具奖励');
                //获取道具的图片和道具名
                $propInfo = $this->Activity_model->commonQuery('prop_name,image', ['id' => $k], 'prop');
                $awardList[] = [
                    'award' => $propInfo[0]['prop_name'] . "道具*" . $v['num'],
                    'img' => config_item('img_url') . $propInfo[0]['image'],
                ];
            }
            if (!$res || !$res1) {
                //失败回滚
                $this->Activity_model->db->trans_rollback();
                $this->conn->del(RedisKey::MAGIC_OPEN_LOCK . $uid);
                return $this->serviceResponse(400, '开启魔盒失败，请重试');
            }
        }
        if ($this->Activity_model->db->trans_status() === FALSE) {
            //失败回滚
            $this->Activity_model->db->trans_rollback();
            $this->conn->del(RedisKey::MAGIC_OPEN_LOCK.$uid);
            return $this->serviceResponse(400, '魔盒开启失败');
        }

        $this->Activity_model->db->trans_commit();
        $this->conn->del(RedisKey::MAGIC_OPEN_LOCK.$uid);
        return $this->serviceResponse(200, '魔盒使用成功',$awardList);
    }

    //魔盒开启获得奖品
    public function getMagicAwardList($num = 1)
    {
        $propRate = $this->Activity_model->getMagicPropRate();
        if (empty($propRate)) {
            return false;
        }
        $prop = array_column($propRate, null, 'prid');
        $config = [];
        foreach ($prop as $k => $v) {
            $config[$k] = $v['rate'] * 1000;
        }
        $award = [];
        for ($i = 1; $i <= $num; $i++) {
            $index = rateGetAward($config);
            $award[$index]['num'] += 1;
            $award[$index]['type'] = $prop[$index]['type'];
            if (!$index) {
                return false;
            }
        }
        return $award;
    }

    //获取魔盒方式 通过type区分用户获得魔盒的方式
    public function getMagicBox($uid,$type)
    {
        if (empty($type)) {
            return $this->serviceResponse(400, '参数错误');
        }
        switch ($type) {
            case 2:
                $key = "blidbox_getmagicbox";
                $desc = "盲盒交友获得魔盒";
                break;
            case 3:
                $key = "login_getmagicbox";
                $desc = "登录获得魔盒";
                break;
            case 4:
                $key = "signin_getmagicbox";
                $desc = "签到获得魔盒";
                break;
            default :
                return false;
        }
        //通过$key获取概率
        $rate = $this->Activity_model->getRateFromCaption($key);
        $config = [
            1 => $rate,
        ];
        $statu = rateGetAward($config);
        //获取到魔盒
        if ($statu) {
            $res = $this->Activity_model->addRucksack($uid, 24, 1, $desc);
            if (!$res) {
                return $this->serviceResponse(400, '获得魔盒失败');
            }
                return $this->serviceResponse(200,'获取成功');
        }
    }

    //抽取拼图碎片
    public function getPuzzlePieces($uid)
    {
        if (empty($uid)) {
            return $this->serviceResponse(400,"参数错误");
        }
        //检测活动开启时间
        $status = $this->checkPuzzleTime();
        if ($status == -1) {
            return $this->serviceResponse(400,"活动未开启");
        }
        if ($status == -2){
            return $this->serviceResponse(400,"活动已结束");
        }
        //抽奖劵数量
        $ticketNum = $this->Activity_model->getUserTicket($uid);
        //已经抽取的数量
        $useNum = $this->Activity_model->getUserUseTicket($uid);
        //检测是否有抽取资格
        if ($ticketNum <= $useNum) {
            return $this->serviceResponse(400, '抽奖劵数量不足');
        }
        if ($useNum >= 16){
            return $this->serviceResponse(400, '您已经获取了全部的碎片');
        }
        //上锁
        $res = $this->conn->setNxExpire(RedisKey::ACTIVITY_TICKET_AWARD_LOCK.$uid,1,3);
        if (!$res){
            return $this->serviceResponse(400,'操作太快啦，稍等片刻哦');
        }
        //获取我应该获得的碎片奖励
        $index = $this->getUserPuzzlePieces($uid);
        if (!$index){
            //移除锁
            $this->conn->del(RedisKey::ACTIVITY_TICKET_AWARD_LOCK.$uid);
            return $this->serviceResponse(400,'您已经获取了全部的碎片');
        }
        //将本次抽取的碎片存放在redis中
        $this->Activity_model->addPiecesRedis($uid,$index);
        //将本次抽取的碎片记录到数据库中
        $this->Activity_model->addPiecesDb($uid,$index);
        $this->conn->del(RedisKey::ACTIVITY_TICKET_AWARD_LOCK.$uid);
        return $this->serviceResponse(200,'抽取成功',['index' => $index]);
    }

    //检测抽碎片活动是否开启
    public function checkPuzzleTime()
    {
        list($start, $end) = config_item('ticketActivityTime');
        $taday = date("Y-m-d H:i:s");
        if ($taday < $start) {
            return -1;
        }
        if ($taday > $end) {
            return -2;
        }
        return 1;
    }

    //获取我应该获得的碎片奖励
    public function getUserPuzzlePieces($uid)
    {
        //通过uid获取我已经抽取的碎片集合
        $myPieces = $this->Activity_model->getUserPuzzlePieces($uid);
        $pieces = [];
        foreach ($myPieces as $v) {
            $pieces[$v] = true;
        }
        //判断是否在该区间抽取
        if ($this->haveAllPieces($pieces, [1, 2, 3, 4])) {
            //在该区间获取应该获取的奖励
            return $this->getPieces($pieces, [1, 2, 3, 4]);
        }
        //第二区间
        if ($this->haveAllPieces($pieces, [5, 6, 7, 8, 9, 10])) {
            //在该区间获取应该获取的奖励
            return $this->getPieces($pieces, [5, 6, 7, 8, 9, 10]);
        }
        //第三区间
        if ($this->haveAllPieces($pieces, [11, 12, 13, 14])) {
            //在该区间获取应该获取的奖励
            return $this->getPieces($pieces, [11, 12, 13, 14]);
        }
        //第四区间
        if ($this->haveAllPieces($pieces, [15, 16])) {
            //在该区间获取应该获取的奖励
            return $this->getPieces($pieces, [15, 16]);
        }
        return false;
    }

    //判断是否已经拥有全部碎片
    public function haveAllPieces($pieces, $array)
    {
        foreach ($array as $v) {
            //是否已拥有
            if (empty($pieces[$v])) {
                return true;
            }
        }
        //全部已拥有则不是该区间
        return false;
    }

    //获取应该获取的碎片奖励
    public function getPieces($pieces,$array)
    {
        foreach ($array as $v) {
            //将未获得的奖励放到数组中
            if (empty($pieces[$v])) {
                $award[] = $v;
            }
        }
        //将数组随机打乱
        shuffle($award);
        //返回数组的第一个数据
        return $award[0];
    }

    //集碎片领取奖励
    public function getPuzzleAward($uid,$type,$isRight)
    {
        //是否满足领奖条件
        $status = $this->checkCanPuzzleAward($uid,$type,$isRight);
        if (!$status){
           return $this->serviceResponse(400,'碎片不足');
        }
        //是否已经领取了该奖励
        $status1 = $this->Activity_model->havePuzzleAward($uid,$type,$isRight);
        if($status1){
           return $this->serviceResponse(400,'已经领取过了');
        }
        //领取操作
        //上锁
        $lockKey = RedisKey::ACTIVITY_PUZZLE_AWARD_LOCK.$uid;
        $lock = $this->conn->setNxExpire($lockKey,1,3);
        if (!$lock){
            return $this->serviceResponse(400,'操作太快了，稍后重试');
        }
        //领取奖励操作
        $res = $this->Activity_model->PuzzleAward($uid,$type,$isRight);
        if (!$res) {
            $this->conn->del($lockKey);
            return $this->serviceResponse(400,'参数错误');
        }
        //添加领取记录
        $this->Activity_model->addPuzzleAwardLog($uid,$type,$isRight);
        $this->conn->del($lockKey);
        return $this->serviceResponse(200,'领取成功');
    }

    //是否满足领取奖励条件
    public function checkCanPuzzleAward($uid,$type,$isRight)
    {
        //通过type和isRight来判断用户需要领取该奖励需要的碎片
        switch ($type) {
            //a奖励只有一个
            case 'a':
                $pieces = [1, 2, 3, 4];
                break;
            case 'b':
                $pieces = $isRight ? [1, 5, 6, 7] : [1, 8, 9, 10];
                break;
            case 'c':
                $pieces = $isRight ? [8, 2, 11, 12] : [5, 2, 13, 14];
                break;
            case 'd':
                $pieces = $isRight ? [9, 13, 3, 15] : [6, 11, 3, 16];
                break;
            case 'e':
                $pieces = $isRight ? [10, 14, 16, 4] : [7, 12, 15, 4];
                break;
            default :
                return false;
        }
        //获取我拥有的全部拼图碎片
        $myPieces = $this->Activity_model->getUserPuzzlePieces($uid);
        foreach ($pieces as $v) {
            //是否拥有需要的全部碎片
            if (!in_array($v,$myPieces)) {
                return false;
            }
        }
        return true;
    }

    //拼图活动首页
    public function PuzzleIndex($uid)
    {
        $res = $this->checkPuzzleTime();
        if ($res == -1){
           return $this->serviceResponse(400,'活动未开启');
        }
        if ($res == -2){
           return $this->serviceResponse(400,'活动已结束');
        }
        //获取用户可用的抽奖卷数量
        $ticket = $this->Activity_model->getUserTicket($uid);
        $useTicket = $this->Activity_model->getUserUseTicket($uid);
        $num = $ticket - $useTicket;
        if ($num < 0){
            $num = 0;
        }
        if ($num > 16){
            $num = 16;
        }
        //获取用户获取到的拼图碎片状态 1:已获取 2：未获取
        $indexArr = [];
        $res = $this->Activity_model->getUserPuzzlePieces($uid);
        for ($i = 1; $i <= 16; $i++) {
            $indexArr[$i] = 0;
            foreach ($res as $v) {
                if ($v == $i) {
                    $indexArr[$i] = 1;
                }
            }
        }
        //距离领取下一个抽奖券所需金币
        $useCoin = $this->conn->hGet(RedisKey::ACTIVITY_COIN_NUM, $uid);
        $coin = $this->Activity_model->coinGetTicket();
        $needCoin = 0;
        foreach ($coin as $k => $v) {
            if ($useCoin < $k) {
                $needCoin = $k - $useCoin;
                break;
            }
        }
        if (!$needCoin) {
            $needCoin = "已获得所有奖励";
        }

        //集齐碎片的奖励状态：0：未领取 1：可领取 2：已领取
        $piecesStatus = $this->getPuzzlePiecesStatus($uid);

        $res = [
            'ticketNum' => $num,
            'needCoin' => $needCoin,
            'indexArray' => $indexArr,
            'piecesStatus' => $piecesStatus,
        ];
        return $this->serviceResponse(200,'',$res);
    }

    //获取用户集碎片全部奖励的状态
    public function getPuzzlePiecesStatus($uid)
    {
        $awardArr = [
            'ar' => ['type' => 'a', 'is_right' => 1],
            'br' => ['type' => 'b', 'is_right' => 1],
            'b' => ['type' => 'b', 'is_right' => 0],
            'cr' => ['type' => 'c', 'is_right' => 1],
            'c' => ['type' => 'c', 'is_right' => 0],
            'dr' => ['type' => 'd', 'is_right' => 1],
            'd' => ['type' => 'd', 'is_right' => 0],
            'er' => ['type' => 'e', 'is_right' => 1],
            'e' => ['type' => 'e', 'is_right' => 0],
        ];
        //是否可领取
        $awardList = [];
        foreach ($awardArr as $k => $v) {
            $status = $this->checkCanPuzzleAward($uid, $v['type'], $v['is_right']);
            $awardList[$k] = $status ? 1 : 0;
            if ($status == 1) {
                //是否已领取
                $status1 = $this->Activity_model->havePuzzleAward($uid, $v['type'], $v['is_right']);
                if ($status1) {
                    $awardList[$k] = 2;
                }
            }
        }
        return $awardList;
    }

    //新春礼盒首页
    public function NewYearGiftCaseIndex($uid)
    {
        if (!$uid) {
            return $this->serviceResponse(400, '参数错误');
        }
        list($start, $end) = config_item('newYearCaseTime');
        $time = time();
        if ($time < strtotime($start)) {
            return $this->serviceResponse(400, '活动未开始');
        }
        if ($time > strtotime($end)) {
            return $this->serviceResponse(400, '活动已结束');
        }
        //获取全部的礼盒
        $case = $this->getNewYearCase();
        $res['award'] = $case;
        //获取我已经领取过的礼盒index
        $usedCase = $this->Activity_model->getUsedCaseIndex($uid);
        $usedCase = array_column($usedCase, 'index', 'index');
        //获取我可以领取的全部礼盒
        $canCase = $this->Activity_service->getCanIndex($uid);
        foreach ($case as $k => $v) {
            $status = 0;
            if (!empty($canCase[$v['index']])) {
                $status = 1;
                if (!empty($usedCase[$v['index']])) {
                    $status = 2;
                }
            }
            $res['award'][$k]['status'] = $status;
        }

        $awardIndexArr = array_column($case, 'name', 'index');
        $prop = $this->Activity_model->getPropNameByIds([1, 2, 3, 26, 27, 28, 29, 30]);
        $propIdArr = array_column($prop, 'prop_name', 'id');
        //20条中奖信息
        $awardInfo = $this->Activity_model->getAwardInfo();
        $content = [];
        foreach ($awardInfo as $k => $v) {
            $award = unserialize($v['award']);
            if ($award['prop']) {
                $content[$k] = "用户" . $v['username'] . '开启' . $awardIndexArr[$v['index']] . "获得道具" . $propIdArr[$award['prop']] . "*" . $award['num'];
            } else {
                $text = "用户" . $v['username'] . '开启' . $awardIndexArr[$v['index']] .
                    "获得道具";
                $text1 = '';
                foreach ($award as $key => $value) {
                    $text1 .= $propIdArr[$value['prop']] . "*" . $value['num'];
                }
                $content[$k] = $text . $text1;
            }
        }
        $res['content'] = $content;
        $userInfo = $this->Users_model->getUserInfoByIds($uid);
        $res['userInfo'] = $userInfo[0];
        $myTicket = $this->conn->hGet(RedisKey::ACTIVITY_NEWYEAR_TICKET_NUM, $uid);
        $res['userInfo']['myTicket'] = $myTicket;
        $myCoin = $this->conn->hGet(RedisKey::ACTIVITY_NEWYEAR_USED_COIN, $uid);
        $coinCase = $this->useCoinGetCase();
        foreach ($coinCase as $k => $v) {
            if ($myCoin >= $coinCase[$k] && $myCoin < $coinCase[$k + 1]) {
                $coinAll = $coinCase[$k + 1];
                $index = $k + 1;
            }
        }
        $coinAll = $coinAll ? $coinAll :25;
        $needCoin = $coinAll - $myCoin;
        $awardIndex = $index ?: 1;
        $res['userInfo']['nextAwardInfo'] = $myCoin >= $coinCase[12] ? "已经获取全部奖励" : "已消耗{$myCoin}金币，还需{$needCoin}金币开启{$awardIndexArr[$awardIndex]}";
        return $this->serviceResponse(200, '', $res);
    }

    //礼盒详情
    public function getNewYearCase()
    {
        return [
            [
                'index' => 1,
                'name' => '新春礼盒(小)',
                'award' => 1,
            ],
            [
                'index' => 2,
                'name' => "新春礼盒(中)",
                'award' => 2,
            ],
            [
                'index' => 3,
                'name' => '新春礼盒(大)',
                'award' => [
                    'ticket' => 3,
                    'prop' => [
                        [
                            'prop_id' => 26,
                            'rate' => 50,
                            'num' => 30,
                        ],
                        [
                            'prop_id' => 2,
                            'rate' => 25,
                            'num' => 1,
                        ],
                        [
                            'prop_id' => 3,
                            'rate' => 25,
                            'num' => 1,
                        ]
                    ],
                ],
            ],
            [
                'index' => 4,
                'name' => '如意礼盒(小)',
                'award' => 5,
            ],
            [
                'index' => 5,
                'name' => "如意礼盒(中)",
                'award' => 15,
            ],
            [
                'index' => 6,
                'name' => '如意礼盒(大)',
                'award' => [
                    'ticket' => 30,
                    'prop' => [
                        [
                            'prop_id' => 27,
                            'rate' => 50,
                            'num'   => 5
                        ],
                        [
                            'prop_id' => 1,
                            'rate' => 25,
                            'num'   => 1,
                        ],
                        [
                            'prop_id' => 2,
                            'rate' => 25,
                            'num'   => 1,
                        ],
                    ],
                ]
            ],
            [
                'index' => 7,
                'name' => '吉祥礼盒(小)',
                'award' => 50,
            ],
            [
                'index' => 8,
                'name' => "吉祥礼盒(中)",
                'award' => 150,
            ],
            [
                'index' => 9,
                'name' => '吉祥礼盒(大)',
                'award' => [
                    'ticket' => 250,
                    'prop' => [
                        28,
                        29
                    ],
                ]
            ],
            [
                'index' => 10,
                'name' => '福满礼盒(小)',
                'award' => 500,
            ],
            [
                'index' => 11,
                'name' => "福满礼盒(中)",
                'award' => 1200,
            ],
            [
                'index' => 12,
                'name' => '福满礼盒(大)',
                'award' => [
                    'ticket' => 2000,
                    'prop' => [
                        29,
                        30
                    ],
                ]
            ],
        ];
    }

    //金币对应礼盒
    public function useCoinGetCase()
    {
        //index 礼盒index，value金币数
        return [
            1 => 25,
            2 => 50,
            3 => 100,
            4 => 200,
            5 => 500,
            6 => 1000,
            7 => 2000,
            8 => 5000,
            9 => 10000,
            10 => 20000,
            11 => 50000,
            12 => 100000,
        ];
    }

    //开启礼盒
    public function openNewYearCase($uid, $index)
    {
        if (!$uid || !$index) {
            return $this->serviceResponse(400, '参数错误');
        }
        list($start, $end) = config_item('newYearCaseTime');
        $time = time();
        if ($time < strtotime($start)) {
            return $this->serviceResponse(400, '活动未开始');
        }
        if ($time > strtotime($end)) {
            return $this->serviceResponse(400, '活动已结束');
        }
        //检测用户是否满足开启该礼盒的条件
        $uidUseCoins = $this->useCoinGetCase();
        //获取用户使用的金币
        $usedCoins = $this->conn->hGet(RedisKey::ACTIVITY_NEWYEAR_USED_COIN,$uid);
        if ($uidUseCoins[$index] > $usedCoins) {
            return $this->serviceResponse(400, '消耗金币不够');
        }
        //检测用户是否已经领取该礼盒
        $checkNum = $this->Activity_model->checkUserOpenNewYearCase($uid,$index);
        if ($checkNum['num']) {
            return $this->serviceResponse(400, '已经开启过该礼盒');
        }
        //上锁
        $lockKey = RedisKey::ACTIVITY_OPEN_NEWYEARCASE_LOCK . $uid;
        if (!$this->conn->setNxExpire($lockKey, 1, 3)) {
            return $this->serviceResponse(400, '操作太快啦，稍等片刻哦');
        }
        //开启事务
        $this->Activity_model->db->trans_begin();
        //获取开启礼盒奖励
        $res = $this->openNewYearCaseAward($index);
        if (empty($res)) {
            $this->conn->del($lockKey);
        }
        $prop = [];
        //将奖励道具放到用户背包中、奖励礼券存在redis中
        if (!is_array($res)) {
            $ticketNum = $res;
            unset($res);
            $res['ticket'] = $ticketNum;
        } else {
            $ticketNum = $res['ticket'];
            //添加道具操作
            if (!is_array($res['prop'])) {
                $status = $this->Activity_model->addRucksack($uid, $res['prop'], $res['num'], "开启新春活动{$index}级礼盒获得道具奖励");
                $prop['prop'] = $res['prop'];
                $prop['num'] = $res['num'];
                if ($status == false) {
                    $this->Activity_model->db->trans_rollback();
                    $this->conn->del($lockKey);
                    return $this->serviceResponse(400, '系统错误，请重试!');
                }
            } else {
                foreach ($res['prop'] as $k => $v) {
                    $status = $this->Activity_model->addRucksack($uid, $v, 1, "开启新春活动{$index}级礼盒获得道具奖励");
                    if ($status == false) {
                        $this->Activity_model->db->trans_rollback();
                        $this->conn->del($lockKey);
                        return $this->serviceResponse(400, '系统错误，请重试!');
                    }
                    $prop[$k]['prop'] = $v;
                    $prop[$k]['num'] = 1;
                }
            }
        }
        //增加礼券数
        //获取我的礼券数
        $num = $this->conn->hGet(RedisKey::ACTIVITY_NEWYEAR_TICKET_NUM,$uid) ?:0;
        $this->conn->hMSet(RedisKey::ACTIVITY_NEWYEAR_TICKET_NUM, [$uid => $num + $ticketNum], 86400 * 5);
        //开启礼盒记录到领取记录表中
        if (!empty($prop)) {
            $prop = serialize($prop);
        }else{
            $prop = "";
        }
        $status = $this->Activity_model->openNewYearCaseLog($uid, $index, $ticketNum, $prop);
        if ($status == false) {
            $this->Activity_model->db->trans_rollback();
            $this->conn->del($lockKey);
            $this->conn->hMSet(RedisKey::ACTIVITY_NEWYEAR_TICKET_NUM, [$uid => $ticketNum - $num], 86400 * 5);
            return $this->serviceResponse(400, '系统错误，请重试!');
        }
        if ($this->Activity_model->db->trans_status() === false) {
            $this->Activity_model->db->trans_rollback();
            $this->conn->hMSet(RedisKey::ACTIVITY_NEWYEAR_TICKET_NUM, [$uid => $ticketNum - $num], 86400 * 5);
            $this->conn->del($lockKey);
            return $this->serviceResponse(400, '系统错误，请重试!');
        }
        //成功;
        $this->Activity_model->db->trans_commit();
        //移除锁
        $this->conn->del($lockKey);
        Logs::debug("用户{$uid}开启新春礼盒{$index}获取奖励{$res}",'','newYearOpen');
        return $this->serviceResponse(200, '', $res);
    }

    //通过礼盒index获得开启礼盒的奖励
    public function openNewYearCaseAward($index)
    {
        $res = $this->getNewYearCase();
        foreach ($res as $v) {
            if ($v['index'] == $index) {
                if (!in_array($index, [3, 6, 9, 12])) {
                    return $v['award'] ?: false;
                } else {
                    if (in_array($index, [9, 12])) {
                        return $v['award'] ?: false;
                    } else {
                        $rate = [];
                        foreach ($v['award']['prop'] as $v1) {
                            $rate[$v1['prop_id']] = $v1['rate'];
                            $num[$v1['prop_id']] = $v1['num'];
                        }
                        $prop_id = rateGetAward($rate);
                        $data = [
                            'ticket' => $v['award']['ticket'],
                            'prop' => $prop_id,
                            'num' => $num[$prop_id],
                        ];
                        return $data;
                    }
                }
            }
        }
    }

    //获取我已经满足条件的全部礼盒
    public function getCanIndex($uid)
    {
        $coins = $this->conn->hGet(RedisKey::ACTIVITY_NEWYEAR_USED_COIN,$uid);
        $arr = $this->useCoinGetCase();
        $res = [];
        foreach ($arr as $k => $v){
            if ($coins >= $v){
                $res[$k] = $k;
            }
        }
        return $res;
    }

    //新春礼券兑换奖励
    public function exchangePropByNYTicket($uid, $index)
    {
        if (empty($uid) || empty($index)) {
            return $this->serviceResponse(400, '参数错误');
        }
        list($start, $end) = config_item('newYearCaseTime');
        $time = time();
        if ($time < strtotime($start)) {
            return $this->serviceResponse(400, '活动未开始');
        }
        if ($time > strtotime($end)) {
            return $this->serviceResponse(400, '活动已结束');
        }
        //获取兑换列表
        $exchangeList = $this->nYTicketExchangeList();
        $exchangeListIndex = array_column($exchangeList, null, 'index');
        //获取我兑换该奖励的次数
        $exchangeNum = $this->Activity_model->checkUserExchangeNewYearPropNum($uid, $index);
        //获取我的礼券数
        $ticketNum = $this->conn->hGet(RedisKey::ACTIVITY_NEWYEAR_TICKET_NUM, $uid);
        if ($ticketNum < $exchangeListIndex[$index]['ticket']) {
            return $this->serviceResponse(400, '新春礼券数不足');
        }
        //达到兑换限制
        if (!empty($exchangeNum['num'])) {
            if ($exchangeNum['num'] >= $exchangeListIndex[$index]['limit']) {
                return $this->serviceResponse(400, '该礼物已达到兑换限制');
            }
        }
        $lock_key = RedisKey::ACTIVITY_NEWYEAR_EXCHANGE_LOCK . $uid;
        if (!$this->conn->setNxExpire($lock_key, 1, 3)) {
            return $this->serviceResponse(400, '操作太快了,稍后重试');
        }
        //领奖操作
        //金币
        if ($index == 1) {
            $this->Activity_model->changeCoins($uid, $exchangeListIndex[$index]['coin'], "新春礼券兑换奖励获得金币*{$exchangeListIndex['coin']}");
        } else {
            //道具
            $this->Activity_model->addRucksack($uid, $exchangeListIndex[$index]['propId'], 1, '新春礼券兑换奖励');
        }
        //记录兑换记录
        $this->Activity_model->addNyExchangeLog($uid, $exchangeListIndex[$index]);
        $this->conn->del($lock_key);
        return $this->serviceResponse(200, '兑换成功');
    }

    //新春礼券兑换列表
    public function nYTicketExchangeList()
    {
        return [
            [
                'index' => 1,
                'coin' => 1000,
                'limit' => 100, //兑换上限
                'ticket' => 1,
            ],
            [
                'index' => 2,
                'propId' => 1,
                'limit' => 1, //兑换上限
                'ticket' => 50,
            ],
            [
                'index' => 3,
                'propId' => 2,
                'limit' => 1, //兑换上限
                'ticket' => 10,
            ],
            [
                'index' => 4,
                'propId' => 3,
                'limit' => 1, //兑换上限
                'ticket' => 50,
            ],
            [
                'index' => 5,
                'propId' => 4,
                'limit' => 1, //兑换上限
                'ticket' => 10,
            ],
            [
                'index' => 6,
                'propId' => 5,
                'limit' => 1, //兑换上限
                'ticket' => 2,
            ],
            [
                'index' => 7,
                'propId' => 6,
                'limit' => 1, //兑换上限
                'ticket' => 100,
            ],
            [
                'index' => 8,
                'propId' => 7,
                'limit' => 1, //兑换上限
                'ticket' => 50,
            ],
            [
                'index' => 9,
                'propId' => 8,
                'limit' => 1, //兑换上限
                'ticket' => 10,
            ],
            [
                'index' => 10,
                'propId' => 9,
                'limit' => 1, //兑换上限
                'ticket' => 2,
            ],
            [
                'index' => 11,
                'propId' => 10,
                'limit' => 1, //兑换上限
                'ticket' => 200,
            ],
            [
                'index' => 12,
                'propId' => 11,
                'limit' => 0, //无上限
                'ticket' => 100,
            ],
        ];
    }
}